/*
 * @Author: chentao 
 * @Date: 2022-05-07 14:54:55 
 * @Last Modified by: chentao
 * @Last Modified time: 2022-05-07 17:50:28
 */
//函数的常规参数
function funcName(name: string, age: number) {
    return name + age;
}
const funNameResult = funcName("string", 3)
console.log(funNameResult)
//可选参数
function funcSelect(name: string, age?: number) {
    return name + age ?? 0;
}
const funcSelectResult = funcSelect("selectName", 3);
console.log(`funcSeelctResult${funcSelectResult}`)
//ts的函数数组类型的剩余参数类型
//比如我定义一个函数类型
function funcMoreTotal(...args: number[]) {
    let total = 0;
    for (let i of args) {
        total += i;
    }
    return total
}
const addTotal = funcMoreTotal(1, 2, 3, 4);
console.log(`${addTotal}`);
//ts元组类型的数组剩余参数
function funcMoreMix(...args: [number, string]) {
    console.log(`判断args的数据类型${Object.prototype.toString.call(args)}`);
    console.log(`length:${args.length}`)
    let result: string = ''
    for (let item of args) {
        if (typeof item === 'number') {
            result = result.concat(item.toString())
            console.log(`列表的itemNumber:${result}`)
        } else if (typeof item === 'string') {
            result = result.concat(item)
            console.log(`列表的itemString:${result}`)
        }
    }
    return result;
}
//等同于这个
function funcMoreMix2(arg0: number, arg1: string) {
    return arg0.toString().concat(arg1);
}
const stringNumberTotal = funcMoreMix(123, "string");
console.log(`元组类型1:${stringNumberTotal}`)
const stringNumberTotal2 = funcMoreMix2(123, "string");
console.log(`元组类型2:${stringNumberTotal2}`)

function testModel() {
    console.log("test函数调用")
}
testModel.version = "aaa";
testModel.name = ""
console.log(testModel)